package org.yx.service.smfr.delete_process_path;

import org.yx.exception.BizException;
import org.yx.models.SmfrProPth;
import org.yx.utils.BaseService;
import org.yx.utils.FieldMap;

import com.xiaoleilu.hutool.util.StrUtil;

/**
 * 删除工艺路线
 * @author zxw
 * @since 2018/03/30
**/
public class SmfrDeleteProcessPathService extends BaseService {
	public SmfrDeleteProcessPathOut deleteProcessPath(SmfrDeleteProcessPathIn in) throws Exception {
		if (StrUtil.isBlank(in.getPathCode())) {
			throw new BizException("SYS-0004", new FieldMap("parameter", "pathCode"));
		}

		SmfrProPth oldPath = selectOne(SmfrProPth.class, in.getUserOrgCode(), in.getPathCode());
		if (oldPath == null || oldPath.getPathStatus() == 'D') {
			throw new BizException("SMFR-0002", new FieldMap("pathCode", oldPath.getPathCode()));
		}

		if (oldPath.getPathStatus() == 'H') {
			throw new BizException("SMFR-0003", new FieldMap("pathCode", oldPath.getPathCode()));
		}
		
		oldPath.setPathStatus('D');
		
		update(oldPath,"pathStatus");

		SmfrDeleteProcessPathOut out = new SmfrDeleteProcessPathOut();

		return out;
	}
}